// pages/pictureChange/pictureChange.js
var app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    selectId: 1,
    pictureUrl:"",
    pictureList: [{
        id: 1,
        url: "http://120.24.97.106:8080/picture/rain.gif"
      },
      {
        id: 2,
        url: "http://120.24.97.106:8080/picture/2.png"
      },
      {
        id: 3,
        url: "http://120.24.97.106:8080/picture/3.png"
      },
      {
        id: 4,
        url: "http://120.24.97.106:8080/picture/4.png"
      },
      {
        id: 5,
        url: "http://120.24.97.106:8080/picture/5.png"
      },
    ]
  },

  to_back: function () {

    wx.request({
      url: 'http://120.24.97.106:8081/theme/saveImg',
      method: 'POST',
      data: {
        "userid": app.userid,
        "pictureid": this.data.selectId,
        "pictureUrl": this.data.pictureUrl,
        // "texts":app.p2_toptexts
      },
      success: (result) => {
        //刷新p2
        app.p2_shuaxin=true
        // wx.navigateTo({
        //   url: '../divTheme/divTheme'
        // })
        // this.onLoad();
        wx.navigateBack({
          delta: 1
        })
      }
    });




  },

  selectPic: function (e) {

    var ccc = e.currentTarget.dataset.id; //获取view中的药用currentTarget
    var ddd=e.currentTarget.dataset.pictureurl;
    // console.log(e.currentTarget.dataset)
    app.selectId = ccc
    app.pictureUrl=ddd
    this.setData({
      selectId: ccc,
      pictureUrl:ddd
    })


  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      selectId: app.selectId
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    wx.request({
      url: 'http://120.24.97.106:8081/theme/saveImg',
      method: 'POST',
      data: {
        "userid": app.userid,
        "pictureid": this.data.selectId,
        "pictureUrl": this.data.pictureUrl,
        // "texts":app.p2_toptexts
      },
      success: (result) => {
        //刷新p2
        app.p2_shuaxin=true
        // wx.navigateTo({
        //   url: '../divTheme/divTheme'
        // })
        // this.onLoad();
        // wx.navigateBack({
        //   delta: 1
        // })
      }
    });
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})